package com.uphone.magicleafteacher.pro.activity.listenertrainlist;

import android.view.View;

import com.blankj.utilcode.util.ToastUtils;
import com.uphone.magicleafteacher.MyApp;
import com.uphone.magicleafteacher.base.BaseListActivity;
import com.uphone.magicleafteacher.http.ApiService;
import com.uphone.magicleafteacher.pro.activity.ListenerTrainActivity;
import com.uphone.magicleafteacher.pro.adapter.ListenerTrainListAdapter;
import com.uphone.magicleafteacher.util.CommonUtil;
import com.uphone.magicleafteacher.util.GsonUtils;
import com.uphone.magicleafteacher.vo.AudioGuideBean;

import java.util.List;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

public class ListenerTrainListActivity extends BaseListActivity<AudioGuideBean.AudioWorkListBean, ListenerTrainListAdapter> {


    @Override
    protected Observable<ResponseBody> loadData(ApiService apiService) {
        return MyApp.apiService(ApiService.class)
                .studentAudioGuide(CommonUtil.getTeacherId(), "" + page, "10");
    }

    @Override
    protected List<AudioGuideBean.AudioWorkListBean> getDataList(String json) {
        AudioGuideBean bean = GsonUtils.getGson().fromJson(json, AudioGuideBean.class);
        if (bean != null)
            return bean.getAudioWorkList();
        return null;
    }

    @Override
    protected void itemClick(ListenerTrainListAdapter adapter, View view, int position) {
        if (adapter.getItem(position).getFinishNum() == 0) {
            ToastUtils.showShort("还未有人完成");
            return;
        }
        CommonUtil.startIntentTitle(this, ListenerTrainActivity.class, mAdapter.getItem(position).getWorkBookId(), mAdapter.getItem(position).getWorkBookName());
    }

    @Override
    protected ListenerTrainListAdapter initAdapter() {
        return new ListenerTrainListAdapter();
    }

    @Override
    protected void initBundle() {

    }

    @Override
    protected void initTitle() {
        initTitle("听力训练");
    }

}
